package day06;

import java.util.Arrays;

/**
 * 数组的复制
 * @author XingHaiYang
 * @date 2022/9/14 14:32
 */
public class ArrayDemo2 {
    public static void main(String[] args) {
        // Arrays.copyOf(原数组，长度)
        int[] arr = {1,2,3,4,5};
        Arrays.copyOf(arr, arr.length+1);//扩容
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        // System.arraycopy(原数组，原数组起始下标，目标数组，目标数组起始下标，长度)
        int[] a = {1,2,3,4,5};
        int[] b = new int[6];
        System.arraycopy(a, 0, b, 0, 5);
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }
    }
}
